package cn.tedu.rabbitmqboot.m4;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 创建队列
 * 绑定交换机
 */
@Component
public class Consumer {
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(/*name = ,durable = ,exclusive = ,autoDelete = */),//不写参数则由服务器自动命名随机队列[非持久,独占,自动删除]false,true,true
            exchange = @Exchange(name = "direct_logs",declare = "false"),//不重复定义这个交换机
            key = {"error"}
    ))
    public void receive1(String msg){
       System.out.println("消费者1,收到消息"+msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(/*name = ,durable = ,exclusive = ,autoDelete = */),//不写参数则由服务器自动命名随机队列[非持久,独占,自动删除]false,true,true
            exchange = @Exchange(name = "direct_logs",declare = "false"),//不重复定义这个交换机
            key = {"info","error","warning"}
    ))
    public void receive2(String msg){
        System.out.println("消费者2,收到消息"+msg);
    }
}
